from django.http import HttpResponseRedirect
from django.shortcuts import render_to_response
from django.newforms import form_for_model, form_for_instance
from blog.blogapp.models import Article, Comment

# Create your views here.

def add_comment(request, slug):
	a = Article.objects.get(slug = slug)
	a.comment_set.create(body = request.POST['comment_text'])
	return HttpResponseRedirect('/%s/' % slug)

def edit_article(request, slug = ''):
	if slug == '':
		ArticleForm = form_for_model(Article)
		form = ArticleForm()
	else:
		article = Article.objects.get(slug = slug)
		form = form_for_instance(article)
	
	return render_to_response('editarticle.html', { 'form': form })

def save_article(request, slug = ''):
	if slug == '':
		ArticleForm = form_for_model(Article)
		form = ArticleForm(request.POST)
		form.slug = 